#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

typedef pair<int, int>PII;


int main()
{
	int n, m, t = 0;
	cin >> n >> m;
	set<PII> s;

	s.insert(PII(0, t++));

	//滚动数组 ,取反建大堆
	for (int i = 0; i < n; i++)
	{
		int i1 = i % 2, i2 = 1 - i1; //当前大顶堆编号 和 上一行大顶堆编号 
		vector<int>temp;
		for (auto x : s)
		{
			temp.push_back(x.first);
		}
		s.clear();

		for (int j = 0, a; j < m; j++)
		{
			cin >> a;
			for (auto x : temp) //和上一行做组合
			{
				if (s.size() < m || s.begin()->first < x - a)
				{
					s.insert(PII(x - a, t++));
				}
				if (s.size() > m) s.erase(s.begin());

			}
		}
	}

	for (auto iter = s.rbegin(); iter != s.rend(); iter++)
	{ 
		cout << -iter->first << " ";
	}

	return 0;
}
